home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Utilities / ResEdit / Examples / CExamples / Source / GNRLLDEF.c next >
Text File  |  2022-08-05  |  3KB  |  97 lines

  1. /*
  2. COPYRIGHT (C) 1984,1985,1986,1988,1989 Apple Computer,Inc.
  3. All rights reserved
  4. */
  5. /* General LDEF proc */
  6.  
  7. #include    <types.h>
  8. #include    <memory.h>
  9. #include    <menus.h>
  10. #include    <resources.h>
  11. #include    <lists.h>
  12. #include    <ToolUtils.h>
  13. #include    <SysEqu.h>
  14.  
  15. #include    "ResEd.h"
  16.  
  17. #define theHiliteMask  0x7FFFFFFF        /* bit 31 */
  18.  
  19. Handle GnrlFetch(short lDataOffset, short *lDataLen, ListHandle lHandle)
  20. {
  21.     short     id;            /* Id is stored in the list - it could be any type. */
  22.     Handle     result;
  23.  
  24.     if (*lDataLen > sizeof(id)) {
  25.         *lDataLen = sizeof(id);                /* Make sure that the length is ok. */
  26.     }
  27.         
  28.     /* Get the id from the list. */
  29.     id = *(short*)((*((*lHandle)->cells)) + lDataOffset);
  30.     SetResLoad(false);                             /* Since all we want is the resinfo */
  31.     result = Get1Res((*((PickHandle)((*lHandle)->refCon)))->rType, id);
  32.     SetResLoad(true);                                /* Always leave this set to true. */
  33.     
  34.     return result;
  35. }
  36.  
  37. /************************************************************************************/
  38.  
  39. void DoHilite (Rect *lRect)
  40. {
  41.             
  42. /* Use the proper hilighting for color. */
  43.  
  44. *(long *)HiliteMode &= theHiliteMask;
  45. InvertRect(lRect);                                /* Select the rectangle. */
  46. }
  47.  
  48. /************************************************************************************/
  49.  
  50. pascal void  DrawCell(short message, Boolean lSelect, Rect *lRect, Point lCell,
  51.                            short lDataOffset, short lDataLen, ListHandle lHandle)
  52. {
  53.     Handle         res;
  54.     ResType        theType;
  55.     short        id;
  56.     Str255        resName;
  57.     FontInfo fInfo;
  58.     
  59.     #pragma    unused (lCell)
  60.  
  61.     switch (message) {
  62.         case lInitMsg:
  63.             /* Set the proper indent distance. */
  64.             GetFontInfo(&fInfo);
  65.             (*lHandle)->indent.h = fInfo.widMax / 3;
  66.             (*lHandle)->indent.v = fInfo.ascent;
  67.             break;
  68.  
  69.         case lDrawMsg:
  70.             if (lDataLen != 0) {
  71.                 res = GnrlFetch(lDataOffset, &lDataLen, lHandle);    /* Get the resource.*/
  72.                 if (res != NULL) {
  73.                     /* If we found the resource, build the string for this resource.*/
  74.                     GetResInfo(res, &id, &theType, &resName);
  75.                     TypeToString(theType, &resName);    /* Put the type into a string.*/
  76.                     SetETitle(res, &resName);                    /* Concatenate the id and the name of the resource. */
  77.                     
  78.                     /* Position the pen. */
  79.                     MoveTo(lRect->left + (*lHandle)->indent.h, lRect->top + (*lHandle)->indent.v);
  80.                     EraseRect(lRect);                                    /* Erase the cell */
  81.                     DrawString(resName);                            /*  and draw the text. */
  82.                     if (lSelect) {                                        /* Hilight if necessary. */
  83.                         DoHilite (lRect);
  84.                     }
  85.                 }
  86.             }
  87.             break;
  88.  
  89.         case lHiliteMsg:
  90.             DoHilite (lRect);
  91.             break;
  92.  
  93.         case lCloseMsg: /* nothing needs to be done here. */
  94.             break;
  95.  
  96.     }
  97. }